﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace InfoMap.Core.UI
{
    /// <summary>
    /// Div Tag class
    /// </summary>
    public class DivTag
    {
        /// <summary>
        /// Height in pixel
        /// </summary>
        public int Height { get; set; }

        /// <summary>
        /// Width in pixel
        /// </summary>
        public int Width { get; set; }

        /// <summary>
        /// Extra styles
        /// </summary>
        /// <example>"float:left;margin-top:5px"</example>
        public string ExtraStyle { get; set; }

        /// <summary>
        /// Id attribute
        /// </summary>
        public string Id { get; set; }

        /// <summary>
        /// String that represents the div tag.
        /// </summary>
        /// <returns>Html generated for the div</returns>
        public override string ToString()
        {
            StringBuilder divTag = new StringBuilder();
            divTag.AppendFormat("<div id='{0}' style='{1}'>", Id, createStyle());
            divTag.AppendLine(@"</div>");
            return divTag.ToString();
        }

        private string createStyle()
        {
            StringBuilder style = new StringBuilder();
            style.AppendFormat("Height:{0}px;Width:{1}px", Height, Width);
            if (!String.IsNullOrEmpty(ExtraStyle))
            {
                style.Append(";");
                style.Append(ExtraStyle);
            }
            return style.ToString();
        }
    }
}
